<template>
  <Modal :mask-closable="false"
      v-model="toggle"
      width="800px"
      class="modal-content-layout"
      :title="`${$t('common.Edit')}`">
    <div>
      <Form
          :show-message="false"
          label-position="top"
      >
        <Row :span="24">
          <p class="info-title">{{ $t('fault.DeviceInformation') }}</p>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                <span>{{ $t('common.company') }}</span>
              </template>
              <p>{{ info.companyName }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                 <span>{{ $t('common.Installation') }}</span>
              </template>
              <p>{{ info.position6 }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                 <span>{{ $t('maintenance.EquipmentNo') }}</span>
              </template>
              <p>{{ info.deviceNo }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                 <span>{{ $t('equipmentscrapped.From') }}</span>
              </template>
              <p>{{ sourceList[info.sbly] }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
               <span>{{ $t('equipmentscrapped.UsedDept') }}</span>
              </template>
              <p>{{ info.useDept }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
               <span>{{ $t('equipmentscrapped.DepartmentalCostCenter') }}</span>
              </template>
              <p>{{ info.deptCostCenter }}</p>
            </FormItem>
          </Col>
          <p class="info-title">{{ $t('preliminary.AssetInformation') }}</p>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                <span>{{ $t('equipmentscrapped.AssetNo') }}</span>
              </template>
              <p>{{ info.assetsNo || '--' }}</p>
            </FormItem>
          </Col>
<!--          <Col :span="12">-->
<!--            <FormItem>-->
<!--              <template #label>-->
<!--                <span style="color: red">*</span>-->
<!--                <span>资产分类：</span>-->
<!--              </template>-->
<!--              <p>{{ info.assetCategory || '&#45;&#45;' }}</p>-->
<!--            </FormItem>-->
<!--          </Col>-->
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                <span>{{ $t('equipmentscrapped.departmentValue') }}</span>
              </template>
              <p>{{ info.assetsOriginal || '--' }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                 <span>{{ $t('equipmentscrapped.ResidualValue') }}</span>
              </template>
              <p>{{ info.assets || '--' }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                 <span>{{ $t('ledger.DepreciationLife') }}</span>
              </template>
              <p>{{ info.depreciation }}</p>
            </FormItem>
          </Col>
          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
               <span>{{ $t('equipmentscrapped.UsedLife') }}</span>
              </template>
              <p>{{ info.useTime }}</p>
            </FormItem>
          </Col>

          <Col :span="12">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                <span>{{ $t('equipmentscrapped.Scrap') }}</span>
              </template>
              <p>{{ info.normalScrap == 1 ? '是' : '否' }}</p>
            </FormItem>
          </Col>
          <Col :span="24">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                <span>{{ $t('spareParts.ScrapReason') }}</span>
              </template>
              <p>{{ info.scrapReason }}</p>
            </FormItem>
          </Col>
          <Col :span="24">
            <FormItem>
              <template #label>
                <span style="color: red">*</span>
                <span>{{ $t('ledger.attachmentinformation') }}</span>
              </template>
              <uploadFile ref="uploadFile" @change="uploadFileChange"/>
            </FormItem>
          </Col>
        </Row>
      </Form>
    </div>
    <div slot="footer">
      <Button type="default" @click="toggle = false">{{ $t('common.Cancle') }}</Button>
      <Button type="primary" :loading="loading" @click="submit">{{ $t('maintenance.Confirmed') }}</Button>
    </div>
  </Modal>
</template>

<script>
import uploadFile from "@/views/devBasic/equipmentscrapped/Scrapapplication/component/uploadFile";

export default {
  name: "approval",
  components: {uploadFile},
  props: ['show', 'row'],
  data() {
    return {
      toggle: false,
      loading: false,
      info: {},
      sourceList: {
        1: '自制',
        2: '内购',
        3: '外购',
        4: '租赁',
        5: '客供',
      },
    }
  },
  watch: {
    show: function (val) {
      if (val) {
        this.toggle = val
        this.getInfo()
      }
    },
    toggle: function (val) {
      if (!val) {
        this.$emit('update:show', val)
      }
    }
  },
  methods: {
    uploadFileChange(attachmentDTOS) {
      this.info.attachmentDTOS = attachmentDTOS
    },
    getInfo() {
      this.axios({
        method: 'get',
        url: '/dms/scrapApply/info',
        params: {
          id: this.row.id
        }
      }).then(res => {
        if (res.code === 200) {
          this.info = res.data
          const attachmentVOS = this.info.attachmentVOS
          this.$nextTick(() => {
            this.$refs.uploadFile.setFiles(attachmentVOS)
          })
        } else {
          this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
        }
      })
    },
    submit() {
      let {attachmentDTOS,orgId,deviceNo,companyId,assetsNo,deviceId,assetsOriginal,depreciation,sbly,useDept,deptCostCenter,normalScrap,useTime,scrapReason} = this.info;
      this.axios({
        method: 'post',
        url: '/dms/scrapApply/update',
        data:{attachmentDTOS,orgId,deviceNo,companyId,assetsNo,deviceId,assetsOriginal,depreciation,sbly,useDept,deptCostCenter,normalScrap,useTime,scrapReason,id:this.row.id}
      }).then(res => {
        if (res.code === 200) {
          this.toggle = false
          this.$Message.success(({content: "编辑成功！", duration: 6, closable: true}));
          this.$emit('change')
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.info-title {
  font-size: 17px;
  color: #000000;
  padding: 0 0 20px 0;
  font-weight: bold;
}

p {
  font-size: 15px;
}
</style>


